package com.claimSettlement.controller;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.UUID;

/**
 * 图片上传控制层
 * 曹文韬
 */
@RestController
@CrossOrigin
@RequestMapping("/surveyLoss")
public class ImgUploadController {

    String path = "http://localhost:7777/fileupload_server/imgs/";

    /*@RequestMapping(value = "/uploadImgs", method = RequestMethod.POST,produces = "text/html;charset=UTF-8")
    public String uploadImgs(@RequestParam("uploadimg") MultipartFile uploadimg) {
        //创建客户端对象
        System.out.println("1:"+uploadimg.getOriginalFilename());
        Client client=Client.create();
        WebResource webResource = null;
        try {
            //for (Map.Entry<String,File> entry:map.entrySet()){
            //MultipartFile multipartFile = FileUtil.fileToMultipartFile(uploadimg);
            if(uploadimg.getOriginalFilename().length() == 0 || uploadimg.getOriginalFilename() == null)return "";
            String fileName = UUID.randomUUID().toString().substring(0,18)+"-" + uploadimg.getOriginalFilename();
            //创建客户端对象
            webResource=client.resource(path+fileName);
            //上传文件到图片服务器
            webResource.put(uploadimg.getBytes());
            //}
        }catch (IOException e) {
            System.out.println(e.getMessage());
        }
        return "成功";
    }*/
}
